import Vue from 'vue'
import Spin from './main.vue'

Spin.instance = properties => {
    const _props = properties || {}

    const Instance = new Vue({
        data: _props,
        render(h) {
            return h(Spin, {
                props: _props
            })
        }
    })

    const component = Instance.$mount()
    document.body.appendChild(component.$el)
    const spin = Instance.$children[0]

    return {
        update(options) {
            if ('show' in options) {
                spin.show = options.show
            }
        },
        component: spin,
        destroy() {
            document.body.removeChild(document.getElementsByClassName('cvu-spin')[0])
        }
    }
}

export default Spin